/*
 * UpdateMPDDialog.java
 *
 * Created on March 28, 2006, 7:24 PM
 */
package com.bff.mpd.musicjukebox.ui.database;

import org.bff.javampd.MPDAdmin;
import com.bff.mpd.utils.Utils;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author  Bill
 */
public class MPDUpdateDialog extends javax.swing.JDialog {

    /** Creates new form UpdateMPDDialog */
    public MPDUpdateDialog(java.awt.Frame parent, MPDAdmin admin, boolean modal) {
        super(parent, modal);

        setUndecorated(true);

        initComponents();
        Utils.centerInParent(this, parent);
        try {
            admin.updateDatabase();

            new Thread(new Runnable() {

                @Override
                public void run() {
                    while (!isVisible()) {
                        try {
                            Thread.sleep(200);
                        } catch (InterruptedException ex) {
                            Logger.getLogger(MPDUpdateDialog.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(MPDUpdateDialog.class.getName()).log(Level.SEVERE, null, ex);
                    }

                    dispose();
                }
            }).start();
            setVisible(true);

        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "MPD is currently updating.");
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("MPD Update");
        getContentPane().setLayout(new java.awt.GridBagLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 102, 255)));
        jPanel1.setPreferredSize(new java.awt.Dimension(300, 100));
        jPanel1.setLayout(new java.awt.BorderLayout());

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("MPD database update has been started.");
        jPanel1.add(jLabel1, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel1, new java.awt.GridBagConstraints());

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
